<?php
class Upload_model extends CI_Model{

	public function __construct(){
		parent::__construct();
		
	}

	public function upload($fieldname=false,$conf = false){
	  $this->load->helper('url');
	  $config['upload_path'] = './data/upload/';
	  $config['allowed_types'] = 'gif|jpg|png';
	  $config['max_size'] = 2*1024;
	  $config['max_width']  = '1024';
	  $config['max_height']  = '768';
	  $config['file_name']  = time();
	  
	  if($conf){
			$config = array_merge($config,$conf);
	  }
	  
	  if(!file_exists($config['upload_path'])){
			mkdir($config['upload_path'],'0644',true);
	  }
	  
	  $this->load->library('upload', $config);
		
	  if($fieldname){
		$up = $this->upload->do_upload($fieldname);
	  }else{
		$up = $this->upload->do_upload();
	  }

	  if ( ! $up)
	  {
		return  $error = array('error' => $this->upload->display_errors());
	
	  }
	  else
	  {
	   return $data = $this->upload->data();

	  }
	}
}